package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/*
* 执行DQL语句
* */
public class JDBCDemo4 {
    public static void main(String[] args) {
        try(
                Connection connection = DBUtile.getConnection();
                ) {

            Statement statement = connection.createStatement();
            String sql = "SELECT id,name,salary,title " +
                    " FROM teacher";
            /*
            * ResultSet重要方法：
            * boolean next()
            * 让结果集向下移动一行，返回值表示是否存在下一行，
            * 如果存在下一行则返回true 否则返回false
            * */
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()){
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                int salary = resultSet.getInt("salary");
                String title = resultSet.getString("title");
                System.out.println(id+name+salary+title);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
